﻿using KINLO.MES.MESModels;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KINLO.MES.MESMachineVoid
{
    public class WinderWebApi
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(WinderWebApi));
        public static int MESWinderInRecord(MESWinderInRecordModel data)
        {
            try
            {
                var sendmsg = JsonConvert.SerializeObject(data);
                log.Info($"【MES卷芯上料入站接口】MES上传信息:{sendmsg}");
                var Result = WebAPIClass.UpLoad_Mes("", sendmsg).Result;
                log.Info($"【MES卷芯上料入站接口】MES返回信息:{Result}");
                if (Result != null)
                {
                    var rspResult = JsonConvert.DeserializeObject<MESResultModel>(Result);
                    if (rspResult.code == "00" && rspResult.message == "ok")
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    return 2;
                }
            }
            catch (Exception ex)
            {
                log.Error($"【MES卷芯上料入站接口】MES上传发生错误:{ex.ToString()}");
                return -1;
            }
        }
        public static int MESWinderOutRecord(MESWinderOutRecordModel data)
        {
            try
            {
                var sendmsg = JsonConvert.SerializeObject(data);
                log.Info($"【MES装盘机出站履历接口】MES上传信息:{sendmsg}");
                var Result = WebAPIClass.UpLoad_Mes("", sendmsg).Result;
                log.Info($"【MES装盘机出站履历接口】MES返回信息:{Result}");
                if (Result != null)
                {
                    var rspResult = JsonConvert.DeserializeObject<MESResultModel>(Result);
                    if (rspResult.code == "00" && rspResult.message == "ok")
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    return 2;
                }
            }
            catch (Exception ex)
            {
                log.Error($"【MES装盘机出站履历接口】MES上传发生错误:{ex.ToString()}");
                return -1;
            }
        }
    }
}
